#ifndef I2C1_H
#define I2C1_H

#include <stdint.h>
#include "gd32f4xx_i2c.h"

#define SCL   GPIO_PIN_1 
#define SDA   GPIO_PIN_0
#define DELAY			delay_I2C(1000)
//	定义PCA9555（NXP半导体I/O扩展芯片，I2C接口）	  
#define  PCA9555_SLA             (0x40 >> 1)    //  定义PAC9555的器件地址    
#define  PCA9555_REG_IN0         0x00   //  定义输入寄存器0地址    
#define  PCA9555_REG_IN1         0x01   //  定义输入寄存器1地址    
#define  PCA9555_REG_OUT0        0x02   //  定义输出寄存器0地址    
#define  PCA9555_REG_OUT1        0x03   //  定义输出寄存器1地址    
#define  PCA9555_REG_POL0        0x04   //  定义极性反转寄存器0地址    
#define  PCA9555_REG_POL1        0x05   //  定义极性反转寄存器1地址 
#define  PCA9555_REG_CFG0        0x06   //  定义方向配置寄存器0地址    
#define  PCA9555_REG_CFG1        0x07   //  定义方向配置寄存器1地址      
#define  PCA9555_ADDR            0x40   //  定义PCA9555地址 

typedef enum I2C_out_dir
{
    eOut,
    eIn
}I2C_out_dir_t;


extern void I2C1_Init(void);
extern void I2C_Port_Init(void);
extern void I2C_Write_Pca9555(uint8_t addr,uint8_t reg_addr,uint8_t low_byte,uint8_t high_byte);
extern void I2C_Read_Pca9555(uint8_t addr,uint8_t reg_addr,uint8_t* pBuffer,uint16_t num);

extern void I2C1_Write_Pca9555(uint8_t addr,uint8_t reg_addr,uint8_t *buf,uint8_t len);
extern void I2C1_Read_Pca9555(uint8_t addr,uint8_t reg_addr,uint8_t* pBuffer,uint8_t num);

/****************************************************************************************************************/
#define DRI_GPIOF_I2C2_SCL SCL
#define DRI_GPIOF_I2C2_SDA SDA

#define DRI_I2C2_SCL_PIN                   	DRI_GPIOF_I2C2_SCL
#define DRI_I2C2_SCL_PORT                   GPIOF
#define DRI_I2C2_SDA_PIN                   	DRI_GPIOF_I2C2_SDA
#define DRI_I2C2_SDA_PORT                   GPIOF

#define DRI_I2C_SCL_LOW                 	(GPIO_BC(DRI_I2C2_SCL_PORT) |= DRI_GPIOF_I2C2_SCL)									
#define DRI_I2C_SCL_HIGH                	(GPIO_BOP(DRI_I2C2_SCL_PORT) |= DRI_GPIOF_I2C2_SCL)

#define DRI_I2C_SDA_LOW                 	(GPIO_BC(DRI_I2C2_SDA_PORT) |= DRI_GPIOF_I2C2_SDA)
#define DRI_I2C_SDA_HIGH                	(GPIO_BOP(DRI_I2C2_SDA_PORT) |= DRI_GPIOF_I2C2_SDA)
#define DRI_I2C_SDA_READ                	(GPIO_ISTAT(DRI_I2C2_SDA_PORT) & DRI_GPIOF_I2C2_SDA)

#define DRI_I2C_ACK						0		//应答  /*注意从机的应答电平*/
#define DRI_I2C_NOACK					1   	//非应答

#define DRI_I2C_SPEED_DATA 				4	 	 //5us 100kbps

#define DRI_I2C_EEPROM_WORD_ADDR_SIZE   8

#define DRI_I2C_EEPROM_WD               0x00                     //写
#define DRI_I2C_EEPROM_RD               0x01                    //读

extern void dri_i2c_read_nbyte(uint8_t slaveAddr, uint16_t regAddr, uint8_t *pData, uint16_t dataLength);
extern void dri_i2c_write_nbyte(uint8_t slaveAddr, uint16_t regAddr, uint8_t *pData, uint16_t dataLength);
#endif

